package com.zmn.plat.services.impl.pilot;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.pilot.ChannelPriceCity;
import com.zmn.plat.model.entity.pilot.ChannelPriceCityQuery;
import com.zmn.plat.model.entity.pilot.CityIdAndName;
import com.zmn.plat.persistence.interfaces.pilot.ChannelPriceCityDao;
import com.zmn.plat.services.interfaces.pilot.ChannelPriceCityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 渠道试点执行城市接口实现类
 *
 * @author guoqiao
 * @since 2021-06-25 10:16:42
 */
@Slf4j
@Service
public class ChannelPriceCityServiceImpl implements ChannelPriceCityService {

    private static final String TAG = "渠道试点执行城市基础服务接口";

    @Resource
    private ChannelPriceCityDao channelPriceCityDao;

    @Override
    public ChannelPriceCity findById(Integer relationId) {

        if (Objects.isNull(relationId)) {
            log.error("[{}],根据id查询数据relationId为null", TAG);
            return null;
        }
        return channelPriceCityDao.findById(relationId);
    }

    @Override
    public List<ChannelPriceCity> listPageByQuery(ChannelPriceCityQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(channelPriceCityDao.countByQuery(query));
        return channelPriceCityDao.listPageByQuery(query);
    }

    @Override
    public List<ChannelPriceCity> listByQuery(ChannelPriceCityQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return channelPriceCityDao.listByQuery(query);
    }

    @Override
    public List<CityIdAndName> listNameByChannelPriceIds(List<Integer> channelPriceIds, Integer type) {
        return channelPriceCityDao.listNameByChannelPriceIds(channelPriceIds, type);
    }

    @Override
    public Integer countByQuery(ChannelPriceCityQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return channelPriceCityDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ChannelPriceCity channelPriceCity) {

        if (Objects.isNull(channelPriceCity.getRelationId())) {
            log.error("[{}],根据id修改数据,channelPriceCity为null", TAG);
            return null;
        }
        return channelPriceCityDao.updateByKey(channelPriceCity);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        channelPriceCityDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(ChannelPriceCity channelPriceCity) {

        if (Objects.isNull(channelPriceCity)) {
            log.error("[{}],新增数据,channelPriceCity为null", TAG);
            return null;
        }
        return channelPriceCityDao.insert(channelPriceCity);
    }

    @Override
    public void insertServBatchs(List<ChannelPriceCity> channelPriceCity) {
        channelPriceCityDao.insertServBatchs(channelPriceCity);
    }

    @Override
    public Integer deleteByKey(Integer relationId) {

        if (Objects.isNull(relationId)) {
            log.error("[{}],根据id删除数据,relationId为null", TAG);
            return null;
        }
        return channelPriceCityDao.deleteByKey(relationId);
    }

    @Override
    public Integer deleteByChannelPriceId(Integer channelPriceId) {
        return channelPriceCityDao.deleteByChannelPriceId(channelPriceId);
    }

}